package com.haoniu.web.controller.module;

import com.haoniu.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.haoniu.common.annotation.Log;
import com.haoniu.common.enums.BusinessType;
import com.haoniu.module.domain.database.RoomLei;
import com.haoniu.module.service.RoomLeiService;
import com.haoniu.web.core.base.BaseController;
import com.haoniu.framework.web.page.TableDataInfo;
import com.haoniu.common.base.AjaxResult;

import java.util.List;
/**
 * 房间-雷数 关联 信息操作处理
 *
 * @author houyijun
 * @date 2019-01-29
 */
@Controller
@RequestMapping("/module/roomLei")
public class RoomLeiController extends BaseController
{
    private String prefix = "module/roomLei";

	@Autowired
	private RoomLeiService roomLeiService;

	@RequiresPermissions("module:roomLei:view")
	@GetMapping()
	public String roomLei()
	{
	    return prefix + "/roomLei";
	}

	/**
	 * 查询房间-雷数 关联列表
	 */
	@RequiresPermissions("module:roomLei:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(RoomLei roomLei) {
		startPage();
        List<RoomLei> list = roomLeiService.selectRoomLeiList(roomLei);
		return getDataTable(list);
	}

	/**
	 * 新增房间-雷数 关联
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存房间-雷数 关联
	 */
	@RequiresPermissions("module:roomLei:add")
	@Log(title = "房间-雷数 关联", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(RoomLei roomLei) {
        roomLei.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(roomLeiService.insertRoomLei(roomLei));
	}

	/**
	 * 修改房间-雷数 关联
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		RoomLei roomLei = roomLeiService.selectRoomLeiById(id);
		mmap.put("roomLei", roomLei);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存房间-雷数 关联
	 */
	@RequiresPermissions("module:roomLei:edit")
	@Log(title = "房间-雷数 关联", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(RoomLei roomLei) {
        roomLei.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(roomLeiService.updateRoomLei(roomLei));
	}

	/**
	 * 删除房间-雷数 关联
	 */
	@RequiresPermissions("module:roomLei:remove")
	@Log(title = "房间-雷数 关联", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(roomLeiService.deleteRoomLeiByIds(ids));
	}

}
